package com.bdqn.ch02.repository;

import com.bdqn.ch02.pojo.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysUserRepository extends JpaRepository<SysUser, Long> {


    List<SysUser> findByUsrName(String usrName);

    List<SysUser> findByUsrNameAndUsrPassword(String usrName,String usrPassword);

    Long countByUsrName(String usrName);

    List<SysUser> findByUsrNameLike(String usrName);

    @Query(value = "select * from sys_user where usr_role_id=?1",nativeQuery = true)
    List<SysUser> findByRoleId(Long roleId);

    @Query("select u from SysUser u where u.usrRoleId=?1")
    Page<SysUser> findPageByUsrRoleId(Long roleId, Pageable pageable);
}
